package viewmodel;

import items.BetItem;
import android.app.betmein.R;
import android.app.betmein.activity.DisplayBetActivity;
import android.app.betmein.view.BetManagementJudgmentTabView;
import android.app.betmein.view.ViewCreatorHelper;
import android.content.Context;
import android.framework.binding.BindableList;
import android.framework.binding.Binding;
import android.framework.binding.ItemList;
import android.framework.paging.BaseViewModel;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import componentes.CommunicationManager;

public class BetManagementJudgmentTabViewModel extends BaseViewModel<BetManagementJudgmentTabView> {

	private ItemList<BetItem> bets;
	
	public BetManagementJudgmentTabViewModel(Context context) {
		super(context);
		bets = new ItemList<BetItem>(context, R.layout.single_judgment_bet, ViewCreatorHelper.judgmentBetListViewCreator());
	}

	
	
	@Override
	public void onInit() {
		getView().bets.setAdapter(bets);
		
		BindableList<BetItem> judgmentBets = CommunicationManager.getInstance().getJudgmentBets();
		bets.addAll(judgmentBets);
		Binding.attached(judgmentBets, bets);
		
		getView().bets.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> adapter, View arg1, int pos,
					long arg3) {
				BetItem betItem = (BetItem)adapter.getItemAtPosition(pos);
				startActivity(DisplayBetActivity.class, betItem.getBet());
			}
		});
	}

}
